<?php
namespace Inter\ArticleBundle\Model;

use Inter\ArticleBundle\Util\SlugifyInterface;
use Inter\ArticleBundle\Model\ArticleInterface;

/**
 * Abstract Article Manager implementation which can be used as a base class
 * for your concrete manager
 */
abstract class ArticleManager implements ArticleManagerInterface
{
	/**
	 * @var $slugifySlug
	 */
	protected $slugSlugify;
	
	/**
	 * Constructor
	 */
	public function __construct(SlugifyInterface $slugSlugify)
	{
		$this->slugSlugify = $slugSlugify;
	}
	
	/** (non-PHPdoc)
	 * @see \Inter\ArticleBundle\Model\ArticleManagerInterface::createArticle()
	 */
	public function createArticle() {
		$class = $this->getClass();
		$article = new $class;
		
		return $article;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see \Inter\ArticleBundle\Model\ArticleManagerInterface::updateSlugField()
	 */
	public function updateSlugField(ArticleInterface $article)
	{		
		$article->setSlug($this->slugifySlug($article->getTitle()));
	}
	/**
	 * 
	 * @param string $text
	 */
	protected function slugifySlug($text)
	{
		return $this->slugSlugify->slugify($text);
	}

}